namespace Ellwood.Manage.MentApi.Utility.RegisterExt;

/// <summary>
/// 跨域扩展
/// </summary>
public static class CorsServiceExtension
{

    /// <summary>
    /// 配置支持跨域策略
    /// </summary>
    /// <param name="builder"></param>
    public static void CorsDomainPolicy(this WebApplicationBuilder builder)
    {
        builder.Services.AddCors(options =>
        {
            // 所有的api都支持跨域
            options.AddPolicy("AllCorsDomainPolicy", corsbuilder =>
            {
                corsbuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
            });
        });
    }

    /// <summary>
    /// 配置生效
    /// </summary>
    /// <param name="app"></param>
    public static void UseCorsDomainPolicy(this WebApplication app)=> 
                                                        app.UseCors("AllCorsDomainPolicy");

}